// components/like/like.js
import {
  commentLike,
  VideoLike,
  Videosc
} from "../../utils/api.js"
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    likeCount: {
      type: Number,
      value: 999
    },
    size: {
      type: Number,
      value: 20
    },
    pullLeft: {
      type: Number,
      value: 0
    },
    isliked: {
      type: Boolean,
      value: false
    },
    cid: {
      type: Number,
      value: 0
    },
    vid: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    animationUp: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    _onUpTap: function(e) {
      var animationUp = wx.createAnimation({
        timingFunction: 'ease-in-out'
      })
      this.animationUp = animationUp;
      this.animationUp.scale(2).step();
      this.setData({
        animationUp: this.animationUp.export(),
      });
      var add = e.target.dataset.dis;
      var cation = add == 1 ? true : false;

      this._videoLike(add, cation);

    },

    _videoLike: function(dis, cation) {
      Videosc(this.data.vid, cation, (res) => {
        console.log(res);
        if (res.errcode == 0 && res.errmsg == "success") {
          this.animationUp.scale(1).step();
          this.setData({
            likeCount: Number(this.data.likeCount) + Number(dis),
            isliked: dis == 1 ? true : false,
            animationUp: this.animationUp.export(),
          });
          var like = wx.getStorageSync("videoLike");
          if (!like) like = {};
          like[this.data.vid] = cation;
          wx.setStorageSync("videoLike", like);
          console.log("end")
        }
      })
    }
  }

})